using StructureMap;

namespace Searchtools.Factories
{
    ///<summary>
    ///</summary>
    public sealed class Ioc
    {
        /// <summary>
        /// Static constructor, initialise structuremap in attribute mode
        /// </summary>
        static Ioc()
        {
            StructureMapConfiguration.UseDefaultStructureMapConfigFile = false;
            StructureMapConfiguration.ScanAssemblies().IncludeTheCallingAssembly();
        }

        private Ioc()
        {
        }

        ///<summary>
        ///</summary>
        ///<typeparam name="T"></typeparam>
        ///<returns></returns>
        public static T Resolve<T>()
        {
            return ObjectFactory.GetInstance<T>();
        }

        ///<summary>
        ///</summary>
        ///<param name="name"></param>
        ///<typeparam name="T"></typeparam>
        ///<returns></returns>
        public static T Resolve<T>(string name)
        {
            return ObjectFactory.GetNamedInstance<T>(name);
        }
    }
}